using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class MetaGroup : EveProperty
    {
        private string metaGroupName;
        private string description;
        private int graphicId;

        private Graphic graphic;
        private List<MetaType> metaTypes;

        public string Name
        {
            get { return metaGroupName; }
        }
        public string Description
        {
            get { return description; }
        }
        public Graphic Graphic
        {
            get
            {
                if (graphic == null)
                    graphic = new Graphic(db, graphicId);
                return graphic;
            }
        }
        public List<MetaType> MetaTypes
        {
            get
            {
                if (metaTypes == null)
                {
                    metaTypes = new List<MetaType>();
                    string query = "SELECT * FROM invMetaTypes WHERE metaGroupID=" + Id;
                    foreach (DbDataRow row in db.ExecuteQuery(query))
                        metaTypes.Add(new MetaType(row));
                }
                return metaTypes;
            }
        }

        internal MetaGroup(DbDataRow dr)
            : base(dr.Database, EvePropertyType.MetaGroup, dr["metaGroupID"])
        {
            Fill(dr);
        }
        internal MetaGroup(Database db, int id)
            : base(db, EvePropertyType.MetaGroup, id)
        {
            Fill(db.ExecuteSingle("SELECT * FROM invMetaGroups WHERE metaGroupID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            metaGroupName = dr["metaGroupName"];
            description = dr["description"];
            graphicId = dr["graphicID"];
        }
    }
}
